package com.wctj.api.business.common.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wctj.api.base.entity.DdwxMemberMoneyLog;
import com.wctj.api.business.common.dao.DdwxMemberMoneyLogMapper;
import com.wctj.api.business.common.dto.DdwxMemberDTO;
import com.wctj.api.business.common.dto.DdwxPayOrderDTO;
import com.wctj.api.business.common.dto.DdwxRechargeOrderDTO;
import com.wctj.api.business.common.service.DdwxMemberMoneyLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

@Service
public class DdwxMemberMoneyLogServiceImpl extends ServiceImpl<DdwxMemberMoneyLogMapper, DdwxMemberMoneyLog> implements DdwxMemberMoneyLogService {
    @Autowired
    private DdwxMemberMoneyLogMapper ddwxMemberMoneyLogMapper;

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void addCmbRechargeRecord(DdwxMemberDTO ddwxMemberDTO, DdwxPayOrderDTO ddwxPayOrderDTO, DdwxRechargeOrderDTO ddwxRechargeOrderDTO, String amount) {
        DdwxMemberMoneyLog moneyLog = new DdwxMemberMoneyLog();
        moneyLog.setAid(ddwxPayOrderDTO.getAid());
        moneyLog.setMid(Integer.valueOf(ddwxMemberDTO.getId()+""));
        moneyLog.setMoney(ddwxMemberDTO.getMoney());
        moneyLog.setAfter(new BigDecimal(amount).add(ddwxMemberDTO.getMoney()));
        moneyLog.setCreatetime((int) System.currentTimeMillis());
        moneyLog.setRemark(ddwxPayOrderDTO.getTitle());
        moneyLog.setFromMid(0); //todo 需再次确认  这个字段怎么存放值
        moneyLog.setPaytype(ddwxRechargeOrderDTO.getPaytype());
        moneyLog.setRechargeid(Math.toIntExact(ddwxRechargeOrderDTO.getId()));
        baseMapper.insert(moneyLog);
    }
}
